package com.xgjweb.common.action;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.Converter;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class XgjWebForm extends ActionForm {
	//开始时间
	protected Date start_date;
	//结束时间
	protected Date end_date;
	static {
		ConvertUtils.register(new DateConverter(), Date.class);
	}

	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		// TODO Auto-generated method stub
		return super.validate(mapping, request);
	}

	public Date getStart_date() {
		return start_date;
	}

	public void setStart_date(Date start_date) {
		this.start_date = start_date;
	}

	public Date getEnd_date() {
		return end_date;
	}

	public void setEnd_date(Date end_date) {
		this.end_date = end_date;
	}
	
	/**
	 * 日期格式化类
	 * @author xgj
	 *
	 */
	final static class DateConverter implements Converter {
		private final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

		@SuppressWarnings("unchecked")
		public Object convert(Class type, Object source) {
			if (source == null || source.equals("")) {
				return null;
			} else if (source instanceof String) {
				Date date = null;
				try {
					date = df.parse((String) source);

				} catch (ParseException e) {
					e.printStackTrace();
				}
				return date;
			} else {
				return null;
			}
		}
	}

}
